// 单指针
fn rs_main1(nums: &mut Vec<i32>) -> &Vec<i32> {
  let mut index = 0;
  let len = nums.len();
  // 查找非零数字并移动
  for i in 0..len {
    if nums[i] != 0 {
      nums[index] = nums[i];
      index += 1;
    }
  }
  // 赋值零
  for i in index..len {
      nums[i] = 0;
  }
  return nums;
}

fn rs_swap(nums: &mut Vec<i32>, left: usize, right: usize) {
  // if (left == right) return;
  let temp = nums[left];
  nums[left] = nums[right];
  nums[right] = temp;
}

// 双指针
fn rs_main2(nums: &mut Vec<i32>) -> &Vec<i32> {
  let mut first_zero_index: usize = 0;
  let len = nums.len();
  for i in 0..len {
    if nums[i] != 0 {
      rs_swap(nums, first_zero_index, i);
      first_zero_index += 1;
    }
  }
  return nums;
}

fn main() {
  let mut test1: Vec<i32> = vec![0, 1, 0, 3, 12];
  rs_main1(&mut test1);
  println!("{:?}", test1);
  let mut test2: Vec<i32> = vec![0, 1, 0, 3, 12];
  rs_main2(&mut test2);
  println!("{:?}", test2);
}
